#include <iostream>
using std::cout;
using std::endl;

#include "Account.h" // include definition of class Account

// Account constructor initializes data member balance
Account::Account( double initialBalance )
{
   balance = 0.0; // assume that the balance begins at 0

   setBalance (initialBalance);
} // end Account constructor

// credit (add) an amount to the account balance
void Account::credit( double amount )
{
   balance = balance + amount; // add amount to balance
} // end function credit

// debit (subtract) an amount from the account balance
bool Account::debit( double amount )
{
   if ( amount <= balance ) // debit amount does not exceed balance
   {
      balance = balance - amount;
      return true;
   }
   else // debit amount exceeds balance
   {
      cout << "Debit amount exceeded account balance.\n" << endl;
      return false;
   }
} // end function debit

void Account::setBalance (double initialBalance)
{
   if ( initialBalance > 0.0 )
      balance = initialBalance;

   if ( initialBalance < 0.0 )
      cout << "Error: Balance cannot be negative.\n" << endl;
}

// return the account balance
double Account::getBalance() const
{
   return balance; // gives the value of balance to the calling function
} // end function getBalance
